<template>
  <div>
    <el-button @click="buy" type="button">采购</el-button>

    <el-table
      :data="list"
      stripe
      style="width: 100%">
      <el-table-column
        type="index"
        width="180">
      </el-table-column>
      <el-table-column
        label="订单编号"
        prop="bh"
        width="180">
      </el-table-column>
      <el-table-column
        label="供应商"
        width="180">
        <template slot-scope="scope">
          {{scope.row.gysid| gys }}
        </template>
      </el-table-column>
      <el-table-column
        label="采购数量"
        prop="num"
        width="180">
      </el-table-column>
      <el-table-column
        label="采购人"
        prop="peo"
        width="180">
      </el-table-column>
      <el-table-column
        label="采购时间"
        width="180">
        <template slot-scope="scope">
          {{scope.row.buytime |timegl }}
        </template>
      </el-table-column>
      <el-table-column
        label="订单状态"
        width="180">
        <template slot-scope="scope">
          {{scope.row.zt |sta }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button type="success" icon="el-icon-check" circle @click="sh(scope.row)" v-if="scope.row.zt==0" ></el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
    import axios from "axios";
    import moment from "moment";
    export default {
        name: "UserList",
      data(){
          return{
            list:[],
          }
      },
      methods:{
          getlist:function () {
            axios.get("http://localhost:8080/list/getlist").then((msg)=>{
              this.list=msg.data;
            })
          },
        sh:function (val) {
              var zt=val.zt;
              var id=val.id;
              var gysid=val.gysid;
              var num=val.num;
              axios.post("http://localhost:8080/list/up/"+zt+"/"+id).then((msg)=>{
                alert(msg);
                axios.post("http://localhost:8080/shop/up/"+gysid+"/"+num).then((msg)=>{
                  this.getlist();

                })

              })
        },
        buy:function () {
            this.$router.push('AddShop');
        }
      },filters:{
        gys:function (id) {
          if(id==1){
            return "可乐工厂"
          }else if(id==2){
            return "手机店"
          }else if(id==3){
            return "批发市场"
          }else{
            return "未录入"
          }
        },
        timegl:function (time){
          return moment(time).format("YYYY-MM-DD hh:mm:ss")
        },
        sta:function (stauts) {
          if(stauts==0){
            return "未审核"
          }else if(stauts==1){
            return  "已转采购"
          }
        }
      },
      mounted() {
          this.getlist();
      }
    }
</script>

<style scoped>

</style>
